<#--
<#function isNumber t>
	return t?conains("numeric") || t?contains("decimal") || t?contains("int") || t?contains("real") || t?contains("float")
</#function>
-->

<#function getEditorValidator f>
	
	<#--validType-->
	<#assign vt = ""/>
	<#assign comma = false/>
	<#if f.validators?? && (f.validators?length > 0)>
		<#list f.validators as V>
			<#assign o_v = getValidator(V)>
			<#if (o_v?length > 0)>
				<#if comma>
					<#assign vt = vt + ", '" + o_v + "">
				<#else>
					<#assign vt = vt + "'" + o_v + "">
				</#if>
				<#assign comma = true>
			</#if>
		</#list>
	</#if>
	<#if (vt?length > 0)>
		<#assign vt = '"validType":[' + vt + "]">
	</#if>
	
	<#assign rs = "">
	<#if isRequried(f)>
		<#assign rs = "required:true">
	</#if>
	
	<#assign os = getEditorOpt(f)>
	
	<#assign et = getEditorType(f)>
	
	<#assign comma = false>
	
	<#assign v = '{"type":"' + et + '", "options":{'>

	<#if (vt?length > 0)>
		<#if comma>
			<#assign v = v + "," + vt + "">
		<#else>
			<#assign v = v + "" + vt + "">
		</#if>
		<#assign comma = true>
	</#if>
	
	<#if (rs?length > 0)>
		<#if comma>
			<#assign v = v + "," + rs>
		<#else>
			<#assign v = v + rs>
		</#if>
		<#assign comma = true>
	</#if>
	
	<#if (os?length > 0)>
		<#if comma>
			<#assign v = v + "," + os>
		<#else>
			<#assign v = v + "" + os>
		</#if>
		<#assign comma = true>
	</#if>

	<#assign v = v + "}}">
	<#return v>
</#function>

<#function isRequried V>
	<#if V.validators?? && (V.validators?length > 0)>
		<#list V.validators as o>
			<#if o.type == "required">
				<#return true>
			</#if>
		</#list>
	</#if>
	<#return false>
</#function>

<#--获取校验器-->
<#function getValidator V>
	<#assign r = "">
	<#if V.type == "stringlength">
		<#assign l_min = "">
		<#assign l_max = "">
		<#list V.params as p>
			<#assign r_add = "">
			<#if p.name == "minLength">
				<#assign l_min = p.value>
			<#elseif p.name == "maxLength">
				<#assign l_max = p.value>
			</#if>
		</#list>
		<#if (l_min?length == 0)>
			<#assign l_min = "0">
		</#if>
		<#if (l_max?length == 0)>
			<#assign l_max = "1000">
		</#if>
		<#assign r = "length[" + l_min + "," + l_max + "]">
	<#elseif V.type == "email">
		<#assign r = "email">
	<#elseif V.type == "url">
		<#assign r = "url">
	<#elseif V.type == "date">
		<#assign r = "date">
	</#if>
	<#return r>
</#function>

<#function getOptions f>
	<#assign opts = "">
	<#if f.options?? && (f.options?length > 0)>
		<#assign opts = opts + ' valueField:"v", textField:"k", data:['>
		<#list f.options as o>
			<#assign opts = opts + '{k:"' + o.label + '", v:"' + o.value + '"}'>
			<#if o_has_next><#assign opts = opts + ','></#if>
		</#list>
		<#assign opts = opts + ']'>
	</#if>
	<#return opts>
</#function>


<#function getRange V>
	<#assign l_min = "">
	<#assign l_max = "">
	<#list V.params as p>
		<#assign r_add = "">
		<#if p.name == "min">
			<#assign l_min = p.value>
		<#elseif p.name == "max">
			<#assign l_max = p.value>
		</#if>
	</#list>
	
	<#assign min = "">
	<#if (l_min?length > 0)>
		<#assign min = "min:">
		<#assign comma1 = ",">
	</#if>
	<#assign max = "">
	<#if (l_max?length == 0)>
		<#assign comma1 = "">
	<#else>
		<#assign max = "max:">
	</#if>
	
	<#return min + l_min + comma1 + max + l_max>
</#function>

<#function getRangeOption f>
	<#assign comma = false>
	<#assign ro_getRangeOption = "">
	<#list f.validators as o>
		<#assign r_getRangeOption = getRange(o)>
		<#if (r_getRangeOption?length > 0)>
			<#if comma>
				<#assign ro_getRangeOption = ro_getRangeOption + ", " + r_getRangeOption + "">
			<#else>
				<#assign ro_getRangeOption = ro_getRangeOption + r_getRangeOption>
			</#if>
			<#assign comma = true>
		</#if>
	</#list>
	<#return ro_getRangeOption>
</#function>

<#function getPrecision t>
	<#return "precision:2">
</#function>
<#--获取编辑器参数-->
<#function getEditorOpt f>
	<#assign combobox = "">
	<#assign jdbcType = f.type?lower_case>
	<#if f.options?? && (f.options?length > 0)>
		<#assign os = getOptions(f)>
		<#assign combobox = ',"editable":false, ' + os>
	</#if>
	
	<#if jdbcType?contains("char")>
		<#return "">
	<#elseif jdbcType?contains("numeric") || jdbcType?contains("decimal")>
		<#assign ro = getRangeOption(f)>
		<#assign precision = getPrecision(jdbcType)>
		<#assign comma1 = "">
		<#if (ro?length > 0) && (precision?length > 0)>
			<#assign comma1 = ",">
		</#if>
		<#return ro + comma1 + precision + combobox>
	<#elseif jdbcType == "bit">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "tinyint">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "smallint">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "int">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "integer">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "bigint">
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "real">
		<#assign ro = getRangeOption(f)>
		<#assign precision = getPrecision(jdbcType)>
		<#assign comma1 = "">
		<#if (ro?length > 0) && (precision?length > 0)>
			<#assign comma1 = ",">
		</#if>
		<#return ro + comma1 + precision + combobox>
	<#elseif jdbcType == "float">
		<#assign ro = getRangeOption(f)>
		<#assign precision = getPrecision(jdbcType)>
		<#assign comma1 = "">
		<#if (ro?length > 0) && (precision?length > 0)>
			<#assign comma1 = ",">
		</#if>
		<#return ro + comma1 + precision + combobox>
	<#elseif jdbcType?contains("binary")>
		<#return getRangeOption(f) + combobox>
	<#elseif jdbcType == "date">
		<#return '"editable":false'>
	<#elseif jdbcType == "datetime">
		<#return '"editable":false'>
	<#elseif jdbcType == "time">
		<#return '"editable":false'>
	<#elseif jdbcType == "timestamp">
		<#return '"editable":false'>
	<#else>
		<#return "">
	</#if>
</#function>

<#--获取编辑器-->
<#function getEditorType f>
	<#assign jdbcType = f.type?lower_case>
	<#if f.options?? && (f.options?length > 0)>
		<#return "combobox">
	</#if>
	<#assign jdbcType = jdbcType?lower_case>
	<#if jdbcType?contains("char")>
		<#return "validatebox">
	<#elseif jdbcType?contains("numeric") || jdbcType?contains("decimal")>
		<#return "numberbox">
	<#elseif jdbcType == "bit">
		<#return "numberbox">
	<#elseif jdbcType == "tinyint">
		<#return "numberbox">
	<#elseif jdbcType == "smallint">
		<#return "numberbox">
	<#elseif jdbcType == "int">
		<#return "numberbox">
	<#elseif jdbcType == "integer">
		<#return "numberbox">
	<#elseif jdbcType == "bigint">
		<#return "numberbox">
	<#elseif jdbcType == "real">
		<#return "numberbox">
	<#elseif jdbcType == "float">
		<#return "numberbox">
	<#elseif jdbcType?contains("binary")>
		<#return "validatebox">
	<#elseif jdbcType == "date">
		<#return "datebox">
	<#elseif jdbcType == "datetime">
		<#return "datetimebox">
	<#elseif jdbcType == "time">
		<#return "datetimebox">
	<#elseif jdbcType == "timestamp">
		<#return "datetimebox">
	<#else>
		<#return "validatebox">
	</#if>
</#function>